<?php /* SVN: $Id: admin_index.ctp 51987 2011-04-28 10:02:04Z aravindan_111act10 $ */ ?>
	<?php 
		if(!empty($this->params['isAjax'])):
			echo $this->element('flash_message');
		endif;
        
        //print_r($dealUserVouchers);
	?>

<?php if(empty($this->params['isAjax']) && empty($this->params['named']['deal_id'])): ?>
	<div class="js-tabs">
           <ul class="clearfix">
                <li><?php echo $html->link(sprintf(__l('All'), $available), array('controller' => 'deal_user_vouchers', 'action' => 'index', 'filter_id' => 'available'), array('title' => __l('Available')));?></li>
                
            </ul>
     </div>
<?php else: ?>
    	<div class="dealUsers index js-response js-responses">
		 <div class="info-details">
			<?php //echo __l("Commission and Purchased amount is calculated only when the deal is closed. You can see the calculated amount in 'Paid to Company' tab."); ?>
		</div>
        <h2><?php echo __l('Deal Backfill');?></h2>
        <?php echo $form->create('DealUserVoucher', array('type' => 'post', 'class' => 'normal search-form clearfix js-ajax-form {"container" : "js-responses"}', 'action'=>'index')); ?>
         <div>
            <?php echo $form->autocomplete('deal_name', array('label' => __l('Deal'), 'acFieldKey' => 'Deal.id', 'acFields' => array('Deal.name'), 'acSearchFieldNames' => array('Deal.name'),'acConditions' => array('Deal.type' => 0), 'maxlength' => '255'));?>
			
            <?php if(!empty($this->data['DealUserVoucher']['filter_id'])): ?>
				<?php echo $form->input('filter_id', array('type' => 'hidden'));?>
            <?php elseif(!empty($this->data['DealUserVoucher']['deal_id'])): ?>
				<?php echo $form->input('deal_id', array('type' => 'hidden'));?>
            <?php endif; ?>
            <?php echo $form->submit(__l('Search'),array('name' => 'data[DealUserVoucher][search]'));?>
        </div>
        <?php echo $form->end(); ?>
		<?php echo $form->create('DealUserVoucher' , array('class' => 'normal js-ajax-form','action' => 'update'));?>
        <?php echo $form->input('r', array('type' => 'hidden', 'value' => $this->params['url']['url'].$param_string)); ?>
        <?php echo $this->element('paging_counter');?>
        <div class="overflow-block">
        <table class="list">
            <tr>
				<?php if(!empty($this->params['named']['filter_id'])  && ($this->params['named']['filter_id'] != 'expired')): ?>
					<th rowspan="2"><?php echo __l('Select'); ?></th>
				<?php endif;?>
                <th rowspan="2"><div class="js-pagination"><?php echo $paginator->sort(__l('Purchased Date'),'DealUser.created');?></div></th>
				<?php if(!empty($this->params['named']['filter_id'])  && ($this->params['named']['filter_id'] == 'canceled')): ?>
	                <th rowspan="2"><div class="js-pagination"><?php echo $paginator->sort(__l('Canceled Date'),'DealUserVoucher.modified');?></div></th>
				<?php endif;?>
                <th rowspan="2" class="dl"><div class="js-pagination"><?php echo $paginator->sort(__l('User'),'User.username');?></div></th>
                <th rowspan="2" class="dl deal-name"><div class="js-pagination"><?php echo $paginator->sort(__l('Deal'), 'Deal.name');?></div></th>
				
                <th rowspan="2" class="dr"><div class="js-pagination"><?php echo $paginator->sort(__l('Price'), 'DealUserVoucher.discount_amount').' ('.Configure::read('site.currency').')';?></div></th>
				<?php if(!empty($this->params['named']['filter_id']) && $this->params['named']['filter_id'] == 'gifted_deals'): ?>
                    <th rowspan="2" class="dl"><div class="js-pagination"><?php echo $paginator->sort(__l('Gift Email'), 'DealUserVoucher.gift_email');?></div></th>
                    <th rowspan="2" class="dl"><div class="js-pagination"><?php echo $paginator->sort(__l('Message'), 'DealUserVoucher.message');?></div></th>
                <?php endif; ?>				
                <th rowspan="2" class="dc"><div class="js-pagination"><?php echo $paginator->sort(__l('Quantity'), 'DealUserVoucher.quantity');?></div></th>       
				<th rowspan="2"><?php echo __l('Purchased City');?></th>
				
            </tr>
			<tr>
				
				
			</tr>
	<?php
        if (!empty($dealUserVouchers)):
        
        $i = 0;
        foreach ($dealUserVouchers as $dealUserVoucher):
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
			if($dealUserVoucher['DealUser']['deal_user_coupon_count'] == $dealUserVoucher['DealUser']['quantity']):
                $status_class = 'js-checkbox-active';
            else:
                $status_class = 'js-checkbox-inactive';
            endif;
        ?>
            <tr<?php echo $class;?>>
			<?php if(!empty($this->params['named']['filter_id'])  && ($this->params['named']['filter_id'] != 'expired')): ?>
                <td>
                    <div class="actions-block">
                        <div class="actions round-5-left">
                            <span><?php echo $html->link(__l('Delete'), array('action' => 'delete', $dealUserVoucher['DealUserVoucher']['id']), array('class' => 'delete js-delete', 'title' => __l('Delete')));?></span>
                           
                        </div>
                    </div>
                <?php echo $form->input('DealUserVoucher.'.$dealUserVoucher['DealUserVoucher']['id'].'.id', array('type' => 'checkbox', 'id' => "admin_checkbox_".$dealUserVoucher['DealUserVoucher']['id'], 'label' => false, 'class' => $status_class.' js-checkbox-list')); ?>
				</td>
				<?php endif;?>
                <td><?php echo $html->cDateTime($dealUserVoucher['DealUserVoucher']['created']);?></td>
				<?php if(!empty($this->params['named']['filter_id'])  && ($this->params['named']['filter_id'] == 'canceled')): ?>
					<td><?php echo $html->cDateTime($dealUserVoucher['DealUserVoucher']['modified']);?></td>
				<?php endif; ?>
                <td class="dl">
                <?php echo $html->getUserAvatarLink($dealUserVoucher['User'], 'micro_thumb',false);?>
                <?php echo $html->getUserLink($dealUserVoucher['DealUser']['User']);?></td>
                <td class="dl deal-name">
					<?php //echo $html->showImage('Deal', $dealUserVoucher['Deal']['Attachment'][0], array('dimension' => 'medium_thumb', 'alt' => sprintf(__l('[Image]'), $html->cText($dealUserVoucher['Deal']['name'], false)), 'title' => $html->cText($dealUserVoucher['Deal']['name'], false)));?>
					<span>
						<?php echo $html->link($html->cText($dealUserVoucher['DealUser']['Deal']['name']), array('controller' => 'deals', 'action' => 'view', $dealUserVoucher['DealUser']['Deal']['slug'], 'admin' => false), array('title'=>$html->cText($dealUserVoucher['DealUser']['Deal']['name'],false),'escape' => false));?>
					</span>
				</td>
				
				<td class="dr"><?php echo $html->cFloat($dealUserVoucher['DealUser']['discount_amount']);?></td>
				<?php if(!empty($this->params['named']['filter_id']) && $this->params['named']['filter_id'] == 'gifted_deals'): ?>
                    <td><?php echo $html->cText($dealUserVoucher['DealUser']['gift_email']);?></td>
                    <td class="dl"><?php echo $html->cText($dealUserVoucher['DealUser']['message']);?></td>
                <?php endif; ?>			
				<td class="dc"><?php echo $html->cInt($dealUserVoucher['DealUser']['quantity']);?></td>  
				<td><?php echo $html->cText($dealUserVoucher['DealUser']['City']['name']);?></td>	
				
            </tr>
        <?php
            endforeach;
        else:
        ?>
            <tr>
                <td colspan="14" class="notice"><?php echo __l('No coupons available');?></td>
            </tr>
        <?php
        endif;
        ?>
        </table>
        </div>
		<?php if (!empty($dealUserVouchers)):?>
			<?php if(!empty($this->params['named']['filter_id'])  && ($this->params['named']['filter_id'] != 'expired')): ?>
            <div class="admin-select-block">
            <div>
                <?php echo __l('Select:'); ?>
                <?php echo $html->link(__l('All'), '#', array('class' => 'js-admin-select-all', 'title' => __l('All'))); ?>
                <?php echo $html->link(__l('None'), '#', array('class' => 'js-admin-select-none', 'title' => __l('None'))); ?>
                <?php if($this->params['named']['filter_id'] == 'all' || (!empty($this->params['named']['deal_id']))) { ?>
                    <?php echo $html->link(__l('Use Now'), '#', array('class' => 'js-admin-select-approved', 'title' => __l('Use Now'))); ?>
                    <?php echo $html->link(__l('Not Used'), '#', array('class' => 'js-admin-select-pending', 'title' => __l('Not Used'))); ?>
                <?php } ?>
            </div>
            <div class="admin-checkbox-button"><?php echo $form->input('more_action_id', array('options' => $moreActions, 'type'=>'select','class' => 'js-admin-index-autosubmit', 'label' => false, 'empty' => __l('-- More actions --'))); ?></div>
            </div>
			<?php endif; ?>
            <div class="js-pagination">
            <?php echo $this->element('paging_links'); ?>
            </div>    
        <?php  endif;  ?>
        <div class="hide">
            <?php echo $form->end('Submit'); ?>
        </div>
        </div>
<?php endif; ?>